export default {
  setMusicList(state, musicList) {
    state.musicList = musicList;
  },
  setPlayState(state, isPlay) {
    state.isPlay = isPlay;
  },
  setCurrenMusicId(state, currenMusicId) {
    state.currenMusicId = currenMusicId;
  },
  setCurrenIndex(state, currenIndex) {
    state.currenIndex = currenIndex;
  },
  setDrawerMusicList(state, drawerMusicList) {
    state.drawerMusicList = drawerMusicList;
  },
  setTotalTime(state, totalTime) {
    state.currenMusicInfo.totalTime = totalTime;
  },
  setCurrenTime(state, currenTime) {
    state.currenMusicInfo.currenTime = currenTime;
  },
  setIsPhone(state, isPhone) {
    state.isPhone = isPhone;
  },
  setIsLogin(state, isLogin) {
    state.isLogin = isLogin;
    if (isLogin) {
      window.localStorage.setItem("isLogin", true);
    } else {
      window.localStorage.removeItem("isLogin");
    }
  },
  setProfile(state, profile) {
  //这里，我还是将这个state搞的有点臃肿！！不过能用
    const newVal = {
      ...state.profile,//将用户的信息结构出来
      ...profile,
    };
    state.profile = newVal;
    localStorage.setItem("profile", JSON.stringify(newVal));
  },
  setAccount(state, account) {
    state.account = account;
    localStorage.setItem("user", account.name);
    localStorage.setItem("token", account.token);
  },
  setHistoryList(state, payload) {
    if (payload.type === "unshift") {
      /* 判断历史播放里是否有重复，这里重复直接不走，也可以删除之前的，再unshift把最新的提到最前面 */
      if (
        state.historyList.findIndex((item) => item.id == payload.data.id) !== -1
      )
        return;
      state.historyList.unshift(payload.data);
      if (state.historyList.length > 50) {
        state.historyList.splice(-1, 1);
      }

      window.localStorage.setItem(
        "historylist",
        JSON.stringify(state.historyList)
      );
      return;
    } else if (payload.type === "get") {
      state.historyList = payload.data;
      return;
    } else if (payload.type === "clear") {
      state.historyList = [];
      window.localStorage.removeItem("historylist");
      return;
    }
  },
  setPlayType(state, playType) {
    if (playType === "music") {
      state.playType = playType;
    }
  },
  setMyPlayList(state, list) {
    state.myPlayList = list;
  },
  setCollectPlayList(state, list){
    state.collectPlayList = list;
  }
};
